package com.to.aboomy.bannersample.component;

import com.to.aboomy.banner.*;
import com.to.aboomy.bannersample.ResourceTable;
import com.to.aboomy.bannersample.util.ToastUtil;
import com.to.aboomy.bannersample.util.Utils;
import com.to.aboomy.bannersample.viewpager.creator.ImageHolderCreator;
import ohos.agp.components.*;
import ohos.agp.utils.Color;
import ohos.app.Context;

/**
 * @author xujianhong
 * @since 2021-07-29
 */
public class ItemPagerNested extends DirectionalLayout {
    public ItemPagerNested(Context context) {
        this(context,null);
    }

    public ItemPagerNested(Context context, AttrSet attrSet) {
        this(context, attrSet,null);
    }

    public ItemPagerNested(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        Component rootView = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_item_pager_nested, this, true);
        Banner banner = (Banner) rootView.findComponentById(ResourceTable.Id_banner);
        Banner banner1 = (Banner) rootView.findComponentById(ResourceTable.Id_banner1);

        banner.setHolderCreator(new ImageHolderCreator())
                .setAutoTurningTime(3000)
                .setPageMargin(-(AttrHelper.vp2px(88,getContext())),AttrHelper.vp2px(37,getContext()))
                .setPageTransformer(true, new ScalePageTransformer())
                .setOnPageClickListener(new OnPageItemClickListener() {
                    @Override
                    public void onPageItemClick(Component view, int position) {
                        ToastUtil.showToast(context,String.valueOf(position));
                    }
                })
                .setPages(Utils.getImage(3));

        banner1.setHolderCreator(new ImageHolderCreator())
                .setAutoTurningTime(3000)
                .setPageMargin(0,0)
                .setOnPageClickListener(new OnPageItemClickListener() {
                    @Override
                    public void onPageItemClick(Component view, int position) {
                        ToastUtil.showToast(context,String.valueOf(position));
                    }
                })
                .setPages(Utils.getImage(3));
    }
}
